package com.rhem.client;

import com.google.gwt.animation.client.Animation;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;

public class GaleriaAnimation extends Animation {
	public AbsolutePanel absolutePanel;
	public HTMLPanel htmlPanel;
	GaleriaAnimation singleton;
	//double start = 0;
	//int repetir = 3;
	int repetir = 2;
	int cont = 1;
	int x_position = 0;
	double mult = 0;
	
	@Override
    protected void onComplete() {
      super.onComplete();
      singleton = this;
      Timer timer = new Timer(){
			@Override
			public void run() {
				singleton.run(1500);
				
			}			
		};
		timer.schedule(7000);
		
		if(cont<repetir){			
			mult = -884;
			if(cont == 1)
				x_position = 0;
			else if(cont == 2)
				x_position = -884;
			
			/*else if(cont == 3)
				x_position = -2*884;*/
				
			cont++;
		}else{
			cont = 1;
			//mult = 1768;
			mult = 884;
			//x_position = -2*884;
			x_position = -884;
			
		}
			
    }


	@Override
	protected void onUpdate(double progress) {		
		updatePosition(htmlPanel, mult*progress + x_position);
	}
	
	private void updatePosition(Widget w, double x) {
		absolutePanel.setWidgetPosition(w, (int) x, 0);
	}

}
